package com.caishi.lkx.common.unionpay.sdk;

import lombok.Builder;
import lombok.Data;

import java.util.List;
@Data
@Builder
public class GetQrCodeBody {
    //消息ID
    String msgId;
    //报文请求时间，格式yyyy-MM-ddHH:mm:ss
    String requestTimestamp;
    //请求系统预留字段
    String srcReserve;
    //商户号
    String mid;
    //终端号
    String tid;
    //业务类型
    String instMid;
    //账单号
    String billNo;
    //账单日期
    String billDate;
    //账单描述
    String billDesc;
    //支付总金额
    int totalAmount;
    //退款金额
    int refundAmount;
    //分账标记
    String divisionFlag;
    //平台商户分账金额
    int platformAmount;
    //商品信息
    List<GoodsItem> goods;
    //子订单信息
    List<SubOrderItem> subOrders;
    //会员号
    String memberId;
    //桌号、柜台号、房间号
    String counterNo;
    //账单过期时间
    String expireTime;
    //支付结果通知地址
    String notifyUrl;
    //网页跳转地址
    String returnUrl;
    //二维码ID
    String qrCodeId;
    //系统ID
    String systemId;
    //担保交易标识
    String secureTransaction;
    //钱包选项
    String walletOption;
    //实名认证姓名
    String name;
    //实名认证手机号
    String mobile;
    //实名认证证件类型
    String certType;
    //实名认证证件号
    String certNo;
    //是否需要实名认证
    String fixBuyer;
    //是否需要限制信用卡支付
    String limitCreditCard;

    String toJson(){
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        if (this.msgId != null) sb.append("\"msgId\":\"" + this.msgId + "\",");
        if (this.requestTimestamp != null) sb.append("\"requestTimestamp\":\"" + this.requestTimestamp + "\",");
        if (this.srcReserve != null) sb.append("\"srcReserve\":\"" + this.srcReserve + "\",");
        if (this.mid != null) sb.append("\"mid\":\"" + this.mid + "\",");
        if (this.tid != null) sb.append("\"tid\":\"" + this.tid + "\",");
        if (this.instMid != null) sb.append("\"instMid\":\"" + this.instMid + "\",");
        if (this.billNo != null) sb.append("\"billNo\":\"" + this.billNo + "\",");
        if (this.billDate != null) sb.append("\"billDate\":\"" + this.billDate + "\",");
        if (this.billDesc != null) sb.append("\"billDesc\":\"" + this.billDesc + "\",");
        if (this.totalAmount != 0) sb.append("\"totalAmount\":\"" + this.totalAmount + "\",");
        if (this.refundAmount != 0) sb.append("\"refundAmount\":\"" + this.refundAmount + "\",");
        if (this.divisionFlag != null) sb.append("\"divisionFlag\":\"" + this.divisionFlag + "\",");
        if (this.platformAmount != 0) sb.append("\"platformAmount\":\"" + this.platformAmount + "\",");
        if (this.goods != null && this.goods.size()>0) {
            sb.append("\"goods\":[");
            for(int i=0;i<goods.size();i++){
                sb.append(goods.get(i));
                sb.append(",");
            }
            if (sb.charAt(sb.length() - 1) == ',')
                sb.deleteCharAt(sb.length() - 1);
            sb.append("],");
        }
        if (this.subOrders != null && this.subOrders.size()>0) {
            sb.append("\"subOrders\":[");
            for(int i=0;i<subOrders.size();i++){
                sb.append(subOrders.get(i));
                sb.append(",");
            }
            if (sb.charAt(sb.length() - 1) == ',')
                sb.deleteCharAt(sb.length() - 1);
            sb.append("],");
        }
        if (this.memberId != null) sb.append("\"memberId\":\"" + this.memberId + "\",");
        if (this.counterNo != null) sb.append("\"counterNo\":\"" + this.counterNo + "\",");
        if (this.expireTime != null) sb.append("\"expireTime\":\"" + this.expireTime + "\",");
        if (this.notifyUrl != null) sb.append("\"notifyUrl\":\"" + this.notifyUrl + "\",");
        if (this.returnUrl != null) sb.append("\"returnUrl\":\"" + this.returnUrl + "\",");
        if (this.qrCodeId != null) sb.append("\"qrCodeId\":\"" + this.qrCodeId + "\",");
        if (this.systemId != null) sb.append("\"systemId\":\"" + this.systemId + "\",");
        if (this.secureTransaction != null) sb.append("\"secureTransaction\":\"" + this.secureTransaction + "\",");
        if (this.walletOption != null) sb.append("\"walletOption\":\"" + this.walletOption + "\",");
        if (this.name != null) sb.append("\"name\":\"" + this.name + "\",");
        if (this.mobile != null) sb.append("\"mobile\":\"" + this.mobile + "\",");
        if (this.certType != null) sb.append("\"certType\":\"" + this.certType + "\",");
        if (this.certNo != null) sb.append("\"certNo\":\"" + this.certNo + "\",");
        if (this.fixBuyer != null) sb.append("\"fixBuyer\":\"" + this.fixBuyer + "\",");
        if (this.limitCreditCard != null) sb.append("\"limitCreditCard\":\"" + this.limitCreditCard + "\",");

        if (sb.charAt(sb.length() - 1) == ',')
            sb.deleteCharAt(sb.length() - 1);
        sb.append("}");
        return sb.toString();
    }

    public String toString(){
        return this.toJson();
    }
    static class GoodsItem {
        //商品ID
        String goodsId;
        //商品名称
        String goodsName;
        //商品数量
        String quantity;
        //商品单价（分）
        String price;
        //商品分类
        String goodsCategory;
        //商品说明
        String body;
        //子商户号
        String subMerchantId;
        //子商户商品总额
        int subOrderAmount;

        String toJson(){
            StringBuilder sb = new StringBuilder();
            sb.append("{");
            if(this.goodsId!=null) sb.append("\"goodsId\":\""+this.goodsId+"\",");
            if(this.goodsName!=null) sb.append("\"goodsName\":\""+this.goodsName+"\",");

            if(this.quantity!=null){
                sb.append("\"quantity\":\""+this.quantity+"\",");
            }
            if(this.price!=null){
                sb.append("\"price\":\""+this.price+"\",");
            }
            if(this.goodsCategory!=null){
                sb.append("\"goodsCategory\":\""+this.goodsCategory+"\",");
            }
            if(this.body!=null){
                sb.append("\"body\":\""+this.body+"\",");
            }
            if(this.subMerchantId!=null){
                sb.append("\"subMerchantId\":\""+this.subMerchantId+"\",");
            }
            if(this.subOrderAmount!=0){
                sb.append("\"subOrderAmount\":\""+this.subOrderAmount+"\",");
            }
            if(sb.charAt(sb.length()-1) == ',')
                sb.deleteCharAt(sb.length()-1);
            sb.append("}");
            return sb.toString();
        }
        public String toString(){
            return this.toJson();
        }
    }
    static class SubOrderItem{
        //子商户号
        String mid;
        //子商户分账金额
        int totalAmount;
        String toJson() {
            StringBuilder sb = new StringBuilder();
            sb.append("{");
            if (this.mid != null) {
                sb.append("\"mid\":\"").append(this.mid).append("\",");
            }
            if (this.totalAmount != 0) {
                sb.append("\"totalAmount\":\"" + this.totalAmount + "\",");
            }
            if (sb.charAt(sb.length() - 1) == ',')
                sb.deleteCharAt(sb.length() - 1);
            sb.append("}");
            return sb.toString();
        }

        public String toString(){
            return this.toJson();
        }
    }

}